/*
 * Line.cpp
 *
 *  Created on: Jul 3, 2009
 *      Author: kurt
 */

#include "Line.h"
#include "DrawingCanvas.h"
#include "GraphicsInstance.h"
#include <GL/gl.h>
#include <sstream>
using namespace std;
using namespace objdraw;
Line::~Line() 
{
	
}

Line::Line() 
{
	start = end = Location(0,0);
	color = Color(0,0,0);
	hidden = false;
	canvas = NULL;
}
Line::Line(float x1, float y1, float x2, float y2, DrawingCanvas * c)
{
	start = Location(x1,y1);
	end = Location(x2,y2);
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
Line::Line(Location _start, Location _end, DrawingCanvas * c)
{
	start = _start;
	end = _end;
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
Line::Line(const Line & r)
{
	start = r.start;
	end = r.end;
	color = r.color;
	hidden = r.hidden;
	canvas = r.canvas;
	
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
void Line::render()
{
	if(hidden) return;
	
	glEnable2D();
	glDisable(GL_TEXTURE_2D);
	
	glBegin(GL_LINES);
		color.use();
		glVertex2f(start.x,start.y);
		glVertex2f(end.x,end.y);
	glEnd();
	
	glDisable2D();
	glDisable(GL_TEXTURE_2D);
}
string Line::toString()
{
	stringstream rstr("Drawable1DInterface: ");
	rstr << "start: " << start.toString() << 
	"end: " << end.toString() << 
	"color: " << color.toString() <<
	"hidden: " << hidden;
	return rstr.str();
}
